package com.tobeface.wechat.message.handler;

import com.google.common.base.Objects;
import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageChannel;
import com.tobeface.wechat.message.WeChatMessagePayloads;
import com.tobeface.wechat.message.WeChatMessageTypes;

/**
 * @author loudyn
 */
public abstract class VideoMessageHandlerSupport extends WeChatMessageHandlerSupport {

    @Override
    protected boolean isMessageTypeSupport(String msgType, WeChatMessage message) {
        if (!Objects.equal(msgType, WeChatMessageTypes.VIDEO)) {
            return false;
        }

        String mediaId = (String) message.getPayloads().get(WeChatMessagePayloads.MEDIAID_PAYLOAD);
        String thumbMediaId = (String) message.getPayloads().get(WeChatMessagePayloads.THUMB_MEDIAID_PAYLOAD);
        return isVideoMessageSupport(message, mediaId, thumbMediaId);
    }

    protected boolean isVideoMessageSupport(WeChatMessage message, String mediaId, String thumbMediaId) {
        return true;
    }

    @Override
    protected final void onMessageReceived(WeChatMessageChannel channel, WeChatMessage message) {
        String mediaId = (String) message.getPayloads().get(WeChatMessagePayloads.MEDIAID_PAYLOAD);
        String thumbMediaId = (String) message.getPayloads().get(WeChatMessagePayloads.THUMB_MEDIAID_PAYLOAD);
        onVideoMessageReceived(channel, message, mediaId, thumbMediaId);
    }

    protected abstract void onVideoMessageReceived(WeChatMessageChannel channel, WeChatMessage message,
                                                   String mediaId, String thumbMediaId);
}
